package org.exhibitj.automation.actions;

import java.awt.Point;

import org.eclipse.swt.widgets.Control;

public class FetchCenterPointOf implements PointTracker {

	private final Control toFindCenterOf;

	public FetchCenterPointOf(Control control) {
		this.toFindCenterOf = control;
	}

	@Override
	public Point fetchPoint() {
		Control control = toFindCenterOf;
		int x = control.getBounds().width / 2;
		int y = control.getBounds().height / 2; // TODO where does 20 come from?
		org.eclipse.swt.graphics.Point display = control.toDisplay(x, y);
		return new Point(display.x, display.y);
//		while (control != null) {
//			x += control.getBounds().x;
//			y += control.getBounds().y;
//			control = control.getParent();
//		}
//		return new Point(x, y);
	}
}
